package cn.tedu.tmall.passport.dao.repository.impl;

import cn.tedu.tmall.passport.dao.repository.IUserCacheRepository;
import cn.tedu.tmall.passport.pojo.po.UserStatePO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import java.io.Serializable;

@Repository
public class UserCacheRepository implements IUserCacheRepository {
    @Autowired
    private RedisTemplate<String, Serializable> redisTemplate;

    @Override
    public void saveUserState(UserStatePO userStatePO) {
        HashOperations<String, Object, Object> hashOperations = redisTemplate.opsForHash();
        String userStateKey = "user_state_"+userStatePO.getId();
        String authorities = userStatePO.getAuthorities();
        Integer enable = userStatePO.getEnable();
        hashOperations.put(userStateKey, "authorities", authorities);
        hashOperations.put(userStateKey, "enable", enable);
    }
}
